import React from 'react'
import PropTypes from 'prop-types'
import { routerRedux } from 'dva/router'
import { connect } from 'dva'
import { Button, Popconfirm } from 'antd'
import { adminCompanyAccoutType } from 'utils/seletLocalData'
import { List, Page } from 'components'
import queryString from 'query-string'
import { ListMenuType } from 'utils/enums'
import styles from '../../themes/list.less'

const CustomerSurplusData = ({ location, dispatch, customerSurplusData, loading }) => {
  location.query = queryString.parse(location.search)
  const { list } = customerSurplusData
  // console.log(customerSurplusData);
  const listProps = {
    dataSource: list,
    loading: loading.effects['customerSurplusData/list'],
    location,
    columnsData: [
      {
        title: 'Index',
        dataIndex: 'index',
        render: (text, record, index) => {
          return (
            <span>
              {index + 1}
            </span>
          )
        },
      },
      {
        title: 'CustomerNumber',
        dataIndex: 'customerNumber',
        key: 'customerNumber',
        render: (text, record) => {
          return (
            <a onClick={() => {
              dispatch(routerRedux.push({
                pathname: `/customersurplus/detail/${record.id}`,
              }))
            }}
            >{text}</a>
          )
        },
      },
      {
        title: 'FristName',
        dataIndex: 'fristName',
        key: 'fristName',
      },
      {
        title: 'CurrencyCode',
        dataIndex: 'currencyCode',
        key: 'currencyCode',
      },
      {
        title: 'Type',
        dataIndex: 'type',
        key: 'type',
        render: (text, record) => {
          let res = ''
          adminCompanyAccoutType.forEach((e) => {
            if (e.key == record.type) {
              res = e.value
            }
          })
          return res
        },
      },
      {
        title: 'BankName',
        dataIndex: 'bankName',
        key: 'bankName',
      },
      {
        title: 'Amount',
        dataIndex: 'amount',
        key: 'amount',
        render: (text, record) => {
          return record.amount.toFixed(4)
        },
      },
    ],
    onChange (page) {
      const { query, pathname } = location
      dispatch(routerRedux.push({
        pathname,
        search: queryString.stringify({
          ...query,
          page: page.current,
          pageSize: page.pageSize,
        }),
      }))
    },
  }

  return (
    <Page inner>
      <List {...listProps} />
    </Page>
  )
}

CustomerSurplusData.propTypes = {
  customerSurplusData: PropTypes.object,
  location: PropTypes.object,
  dispatch: PropTypes.func,
  loading: PropTypes.object,
}

export default connect(({ customerSurplusData, loading }) => ({ customerSurplusData, loading }))(CustomerSurplusData)
